import { Controller, Get, Post, Body, Patch, Param, Delete,Query, Logger } from '@nestjs/common';
import { PostService } from './post.service';
import { CreatePostDto } from './dto/create-post.dto';
import { UpdatePostDto } from './dto/update-post.dto';
import { CreateCommitDto } from './dto/create-commit.dto';
import { ApiTags ,ApiOperation} from '@nestjs/swagger/dist'
import { UpdatePostItemDto } from './dto/update-postItem.dto';

@Controller('post')
@ApiTags('文章相关接口')
export class PostController {
  constructor(private readonly postService: PostService) {}
  @Get('ByUserId')
  @ApiOperation({summary:'根据用户id查找文章',description:"根据用户id查找文章"})
  findByUserId(@Query() query: { userId?: string, page?: number, pageSize?: number }) {
    console.log('走进了ByIdcontroller');
    return this.postService.findByUser(query);
  }
  @Get('ByUserIdList')
  @ApiOperation({summary:'根据用户id查找文章',description:"根据用户id查找文章"})
  findByUserIdList(@Query() query: { userIdList?: string[], page?: number, pageSize?: number }) {
    console.log('走进了ByIdListcontroller');
    return this.postService.findByUserList(query);
  }
  @Get('ByTopicName')
  @ApiOperation({summary:'根据话题圈子名称查找文章',description:"根据话题圈子名称查找文章"})
  findByTopicName(@Query() query: { topic?: string, page?: number, pageSize?: number }) {
    console.log('走进了ByTopicName');
    return this.postService.findByTopicName(query);
  }
  @Get('ByNameLike')
  @ApiOperation({summary:'根据用户文章名称模糊查找文章',description:"根据用户文章名称模糊查找文章"})
  findByName(@Query() query: {name:string}) {
    console.log('走进了ByNameLike');
    return this.postService.findByName(query);
  }


  @Post()
  @ApiOperation({summary:'发表帖子',description:"发表帖子"})
  create(@Body() createPostDto: CreatePostDto) {
    return this.postService.create(createPostDto);
  }
  @Post('commit')
  @ApiOperation({summary:'发表评论',description:"发表评论"})
  createCommit(@Body() createCommitDto: CreateCommitDto) {
    return this.postService.createCommit(createCommitDto);
  }
  @Delete('commit/:id')
  @ApiOperation({summary:'删除评论',description:"删除评论"})
  removeCommit(@Param('id') id: string) {
    return this.postService.removeCommit(id);
  }
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.postService.findOne(id);
  }
  @Get()
  find(@Query() query: { keyword?: string, page?: number, pageSize?: number }) {
    console.log(query);
    console.log('进了没有user的分页查询');
    return this.postService.find(query);
  }
  @Get('all')
  findAll() {
    return this.postService.findAll();
  }


  @Patch('item/:id')
  updateItem(@Param('id') id: string, @Body() updatePostItemDto: UpdatePostItemDto) {
   new Logger('进入更新文章内容')
    console.log('进入更新文章内容');
    
    return this.postService.updatePostItem(id, updatePostItemDto);
  }

  @Patch(':id')
  updateEye(@Param('id') id: string, @Body() updatePostDto: UpdatePostDto) {
    return this.postService.updateEye(id, updatePostDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.postService.remove(id);
  }
}
